home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Online / NNTPd / xmit / xmitauth.c < prev   
Encoding:
C/C++ Source or Header  |  2002-12-03  |  1.3 KB  |  80 lines

  1. #ifndef lint
  2. static char *rcsid = "$Id: xmitauth.c,v 1.7 1994/12/03 21:53:41 sob Exp sob $";
  3. #endif
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include "../conf.h"
  7. #include "../server/nntp.h"
  8. #include "nntpxmit.h"
  9.  
  10. #ifdef AUTH
  11.  
  12. extern char Debug;
  13. extern int converse();
  14.  
  15. FILE *sys;
  16.  
  17. xmitauth(host)
  18. char *host;
  19.     {
  20.     char remote[64], user[16], pass[16];
  21.     char buf[1024];
  22.     int i;
  23.     char savedebug;
  24.  
  25.     sys = fopen(PASSFILE, "r");
  26.     if (sys == NULL)
  27.         {
  28.         exit(1);
  29.         }
  30.     
  31.     while(fgets(buf, sizeof(buf), sys))
  32.         {
  33.         if (buf[0] == '#')
  34.             continue;
  35.         
  36.         i = sscanf(buf,"%s %s %s", remote, user, pass);
  37.         /* malformed entry? */
  38.         if (i != 3)
  39.             {
  40.             log(L_NOTICE,"malformed entry in nntp.sys");
  41.             continue;
  42.             }
  43.         
  44.         /* right host? */
  45.         if (!strcasecmp(remote,host))
  46.             break;
  47.         }
  48.     if (feof(sys))
  49.         {
  50.         sprintf(buf,"host %s authinfo not in nntp.sys", host);
  51.         log(L_NOTICE, buf);
  52.         exit(1);
  53.         }
  54.     
  55.     sprintf(buf,"authinfo user %s", user);
  56.     if (converse(buf, sizeof(buf)) != NEED_AUTHDATA)
  57.         {
  58.         log(L_NOTICE, buf);
  59.         exit(1);
  60.         }
  61.     
  62.     /* don't display the password even if debug is on */
  63.     savedebug = Debug;
  64.     Debug = FALSE;
  65.  
  66.     sprintf(buf,"authinfo pass %s", pass);
  67.     if (converse(buf, sizeof(buf)) != OK_AUTH)
  68.         {
  69.         log(L_NOTICE, buf);
  70.         exit(1);
  71.         }
  72.     
  73.     Debug = savedebug;
  74.  
  75.     fclose(sys);
  76.     }
  77.  
  78. #endif /* AUTH */
  79.  
  80.